package worktime.yft.demo.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import worktime.yft.demo.Entity.Project;
import worktime.yft.demo.Entity.User;
import worktime.yft.demo.Service.ProjectService;
import worktime.yft.demo.Service.RecordService;
import worktime.yft.demo.Service.UserService;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@RestController
@CrossOrigin
public class test {
    @Autowired
    private ProjectService projectService;
    @Autowired
    private UserService userService;
    @RequestMapping("test")
    public void test(){
        try {
            String path = "/home/zhoudongyang/";
            BufferedReader name = new BufferedReader(new InputStreamReader(new FileInputStream(path+"name.txt"), "UTF-8"));
            BufferedReader id = new BufferedReader(new InputStreamReader(new FileInputStream(path+"id.txt"), "UTF-8"));
            BufferedReader dep = new BufferedReader(new InputStreamReader(new FileInputStream(path+"dep.txt"), "UTF-8"));
            String Name = name.readLine(),Id=id.readLine(),Dep=dep.readLine();
            userService.insertUser(new User("uyanz071","uyanz071","软件开发",true,"杨祖乔"));
            while ((Name = name.readLine()) != null){
                Id = id.readLine();
                Dep = dep.readLine();
                userService.insertUser(new User(Id,Id,Dep,true,Name));
            }
            name.close();
            id.close();
            dep.close();
        } catch (Exception e) {
            System.err.println("read errors :" + e);
        }
//        userService.insertUser(new User("he","123456","SW",true,"he"));
        projectService.insert(new Project(false,"E-Concept",""));
        projectService.insert(new Project(false,"SVW demo",""));
        projectService.insert(new Project(false,"空调项目(非E-Concept)",""));
        projectService.insert(new Project(false,"开关项目(非E-Concept)",""));
        projectService.insert(new Project(false,"产品开发流程",""));
        projectService.insert(new Project(false,"EBP-QAD系统搭建",""));
        projectService.insert(new Project(false,"上汽大通",""));
        projectService.insert(new Project(false,"SAIC ER31 8155",""));
        projectService.insert(new Project(false,"SAIC ER31 820A(POC)",""));
        projectService.insert(new Project(false,"享道出行",""));
        projectService.insert(new Project(false,"VW IOF project 德国大众项目",""));
        projectService.insert(new Project(false,"音响",""));
        projectService.insert(new Project(false,"BMW V&L",""));
        projectService.insert(new Project(false,"Pursuit",""));
        projectService.insert(new Project(false,"休假",""));
        projectService.insert(new Project(false,"培训",""));
        projectService.insert(new Project(false,"其他",""));
    }
}
